package com.zhihu_lvliangi_android.option.login;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.zhihu_lvliangi_android.R;
import com.zhihu_lvliangi_android.option.parent.ParentFragment;
import com.zhihu_lvliangi_android.service.DataFormat;
import com.zhihu_lvliangi_android.service.MobileApplication;
import com.zhihu_lvliangi_android.service.TaskID;

/**
 * 登录页
 * 
 * @author azuryleaves
 * @since 2014-12-3 下午3:11:32
 * @version V1.0
 * 
 */
public class LoginFragment extends ParentFragment {

	private EditText account_EditText, password_EditText;
	private Button signin_Button;

	private OnClickListener clickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.login_signin_Button:
				if (checkEmpty()) {
					Map<String, String> map = new HashMap<String, String>();
					map.put("account_name", account_EditText.getText().toString());
					map.put("password", password_EditText.getText().toString());
					MobileApplication.getInstance().clientTask.executePost(TaskID.TASK_LOGIN_SIGNIN, DataFormat.STRING, "请求URL", map, LoginFragment.this);
				}
				break;
			default:
				break;
			}
		}
	};

	private boolean checkEmpty() {
		if ("".equals(account_EditText.getText().toString())) {
			showShortToast("请输入用户名");
		} else {
			if ("".equals(password_EditText.getText().toString())) {
				showShortToast("请输入密码");
			} else {
				return true;
			}
		}
		return false;
	}

	@Override
	protected int getLayoutId() {
		setUseMain_scrollview(false);
		return R.layout.login;
	}

	@Override
	protected void setupViews(View parentView) {
		account_EditText = (EditText) parentView.findViewById(R.id.login_account_EditText);
		password_EditText = (EditText) parentView.findViewById(R.id.login_password_EditText);
		signin_Button = (Button) parentView.findViewById(R.id.login_signin_Button);
	}

	@Override
	protected void initialized(Bundle savedInstanceState) {
		signin_Button.setOnClickListener(clickListener);
	}

	@Override
	public void threadTask() {

	}

	@Override
	public void onResponse(Object response, Enum<?> reqId) {
		super.onResponse(response, reqId);
		
	}

}
